<template>
	<view>
		<view v-if="showUpd">
			<view class="mask"></view>
			<view class="updateBox">
				<view class="tubiao">
					<image src="./ic_ar.png"></image>
				</view>
				<view class="wrapbox">
					<view class="version">发现新版本{{version}}</view>
					<view class="desc-t">本次更新内容：</view>
					<view class="desc">
						<rich-text :nodes="content"></rich-text>
					</view>
					<view class="btnbox">
						<view class="btnno" @click="close">暂不升级</view>
						<view class="btnUp" @click="updClick">立即升级</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {checkVersion,openMarket} from './updhelp.js'
	export default {
		data() {
			return {
				updInfo:{},
				showUpd: false,
				content: '',
				version: ''
			}
		},
		mounted() {
			// #ifdef APP-PLUS
			this._getVersion();
			// #endif
			// #ifdef H5
			this.showUpd = true;
			// #endif
		},
		methods: {
			close(){
				this.showUpd = false;
			},
			updClick(){
				// #ifdef APP-PLUS
				openMarket(this.updInfo);
				// #endif
				// #ifdef H5
				this.showUpd = false;
				// #endif
			},
			_getVersion(){
				this.updInfo = {
					android_content: "紧急更新建议所有用户都升级，修复获取xxx",
					android_v: "15.1.7",
					android_appurl: "market://details?id=io.dcloud.HelloH5",
					android_marketPackageName: "com.tencent.android.qqdownloader",
					android_marketPackageNameTxt: "应用宝",
					ios_content: "紧急更新建议所有用户都升级，修复获取xxx",
					ios_v: "15.1.7",
					ios_appurl: "itms-apps://itunes.apple.com/cn/app/hello-uni-app/id1417078253?mt=8",
				}
				this._initData(this.updInfo);
			},
			_initData(data){
				if (plus.os.name == "Android") {
					this.content = data.android_content;
					this.version = data.android_v;
				} else {
					this.content = data.ios_content;
					this.version = data.ios_v;
				}
				let isUpd = checkVersion(data);
				if(isUpd){
					this.showUpd = true;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mask {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 888;
		background-color: rgba(0, 0, 0, 0.6);
	}

	.btn {
		width: 70%;
		margin: 20rpx auto;
		margin-top: 40rpx;
		padding: 20rpx 0px;
		text-align: center;
		background: #4884FF;
		border-radius: 34px;
		font-size: 30rpx;
		color: #fff;
	}

	.updateBox {
		position: absolute;
		top: 10%;
		z-index: 998;
		height: 300rpx;
		width: 80%;
		left: 10%;

		.tubiao {
			text-align: center;

			image {
				z-index: 999;
				width: 200rpx;
				height: 130rpx;
			}
		}

		.wrapbox {
			position: relative;
			z-index: 998;
			top: -70rpx;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 30rpx 40rpx;

			.version {
				margin-top: 50rpx;
				font-size: 35rpx;
				color: #333;
				font-weight: bold;
				text-align: center;
			}

			.desc-t {
				margin-top: 30rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
	}

	.desc {
		height: 230rpx;
		overflow: scroll;
		margin-top: 10rpx;
		font-size: 30rpx;
		color: #666;
		line-height: 50rpx;
	}

	.btnbox {
		display: flex;
		justify-content: space-around;
		margin: 40rpx 0rpx 20rpx 0rpx;
		margin-top: 50rpx;
		.btnno,.btnUp{
			padding: 20rpx 50rpx;
			border-radius: 10rpx;
			text-align: center;
			font-size: 30rpx;
		}
		.btnno {
			background-color: #f8f8f8;
			color: #666;
		}

		.btnUp {
			background-color: #4884FF;
			color: #fff;
		}
	}
</style>
